package SquarePackage;

import static org.junit.Assert.*;

import org.junit.*;

public class TemperatureScaleTest {

	@Test
	public void testGetSignKelvin() {
		assertEquals("K", TemperatureScale.KELVIN.getSign().toString());
	}

	@Test
	public void testGetSignCelsius() {
		assertEquals("C", TemperatureScale.CELSIUS.getSign().toString());
	}

	@Test
	public void testGetSignFahrenheit() {
		assertEquals("F", TemperatureScale.FAHRENHEIT.getSign().toString());
	}

	@Test
	public void testChangeTemperaturescaleKelvinToKelvin0() {
		assertEquals(0, TemperatureScale.KELVIN.changeTemperatureScale(0,
				TemperatureScale.KELVIN), 0.01);
	}

	@Test
	public void testchangeTemperatureScaleKelvinToKelvin1000() {
		assertEquals(1000, TemperatureScale.KELVIN.changeTemperatureScale(1000,
				TemperatureScale.KELVIN), 0.01);
	}

	@Test
	public void testchangeTemperatureScaleKelvinToCelsius0() {
		assertEquals(-273.15, TemperatureScale.KELVIN.changeTemperatureScale(0,
				TemperatureScale.CELSIUS), 0.01);
	}

	@Test
	public void testchangeTemperatureScaleKelvinToCelsius1000() {
		assertEquals(726.85, TemperatureScale.KELVIN.changeTemperatureScale(
				1000, TemperatureScale.CELSIUS), 0.01);
	}

	@Test
	public void testchangeTemperatureScaleKelvinToFahrenheit0() {
		assertEquals(-459.67, TemperatureScale.KELVIN.changeTemperatureScale(0,
				TemperatureScale.FAHRENHEIT), 0.01);
	}

	@Test
	public void testchangeTemperatureScaleKelvinToFahrenheit1000() {
		assertEquals(1340.33, TemperatureScale.KELVIN.changeTemperatureScale(
				1000, TemperatureScale.FAHRENHEIT), 0.01);
	}

	@Test
	public void testchangeTemperatureScaleCelsiusToKelvin0() {
		assertEquals(273.15, TemperatureScale.CELSIUS.changeTemperatureScale(0,
				TemperatureScale.KELVIN), 0.01);
	}

	@Test
	public void testchangeTemperatureScaleCelsiusToKelvin1000() {
		assertEquals(1273.15, TemperatureScale.CELSIUS.changeTemperatureScale(
				1000, TemperatureScale.KELVIN), 0.01);
	}

	@Test
	public void testchangeTemperatureScaleCelsiusToCelsius0() {
		assertEquals(0, TemperatureScale.CELSIUS.changeTemperatureScale(0,
				TemperatureScale.CELSIUS), 0.01);
	}

	@Test
	public void testchangeTemperatureScaleCelsiusToCelsius1000() {
		assertEquals(1000, TemperatureScale.CELSIUS.changeTemperatureScale(
				1000, TemperatureScale.CELSIUS), 0.01);
	}

	@Test
	public void testchangeTemperatureScaleCelsiusToFahrenheit0() {
		assertEquals(32, TemperatureScale.CELSIUS.changeTemperatureScale(0,
				TemperatureScale.FAHRENHEIT), 0.5);
	}

	@Test
	public void testchangeTemperatureScaleCelsiusToFahrenheit1000() {
		assertEquals(1832, TemperatureScale.CELSIUS.changeTemperatureScale(
				1000, TemperatureScale.FAHRENHEIT), 0.5);
	}

	@Test
	public void testchangeTemperatureScaleFahrenheitToKelvin0() {
		assertEquals(255.37,
				TemperatureScale.FAHRENHEIT.changeTemperatureScale(0,
						TemperatureScale.KELVIN), 0.5);
	}

	@Test
	public void testchangeTemperatureScaleFahrenheitToKelvin1000() {
		assertEquals(810.92,
				TemperatureScale.FAHRENHEIT.changeTemperatureScale(1000,
						TemperatureScale.KELVIN), 0.5);
	}

	@Test
	public void testchangeTemperatureScaleFahrenheitToCelsius0() {
		assertEquals(-17.77,
				TemperatureScale.FAHRENHEIT.changeTemperatureScale(0,
						TemperatureScale.CELSIUS), 0.5);
	}

	@Test
	public void testchangeTemperatureScaleFahrenheitToCelsius1000() {
		assertEquals(537.77,
				TemperatureScale.FAHRENHEIT.changeTemperatureScale(1000,
						TemperatureScale.CELSIUS), 0.5);
	}

	@Test
	public void testchangeTemperatureScaleFahrenheitToFahrenheit0() {
		assertEquals(0, TemperatureScale.FAHRENHEIT.changeTemperatureScale(0,
				TemperatureScale.FAHRENHEIT), 0.5);
	}

	@Test
	public void testchangeTemperatureScaleFahrenheitToFahrenheit1000() {
		assertEquals(1000, TemperatureScale.FAHRENHEIT.changeTemperatureScale(
				1000, TemperatureScale.FAHRENHEIT), 0.5);
	}

	@Test(expected = IllegalArgumentException.class)
	public void testLowerThanZeroKelvinInKelvin() {
		TemperatureScale.KELVIN.changeTemperatureScale(-5,
				TemperatureScale.CELSIUS);
		fail("temperature can't be lower then 0K");
	}

	@Test(expected = IllegalArgumentException.class)
	public void testLowerThanZeroKelvinInCelsius() {
		TemperatureScale.KELVIN.changeTemperatureScale(-300,
				TemperatureScale.CELSIUS);
		fail("temperature can't be lower then 0K");
	}

	@Test(expected = IllegalArgumentException.class)
	public void testLowerThanZeroKelvinInFahrenheit() throws Exception {
		TemperatureScale.KELVIN.changeTemperatureScale(-500,
				TemperatureScale.CELSIUS);
		fail("temperature can't be lower then 0K");
	}

	/**
	 * Test if converting to a non-existing temperature scale.
	 * 
	 * @note this didn't compile, so I commented it.
	 */
	// @Test(expected = IllegalArgumentException.class)
	// public void testFalseScale() {
	// TemperatureScale.FAHRENHEIT.changeTemperatureScale(1000,
	// TemperatureScale.STELLA);
	// fail("not a valid scale");
	// }
}
